< previous page page_307 next page >

Page 307
e10a6a0a59f035e870d90cca05b85fce.gif
        ' To make things faster, only DoEvents
        ' every 100 times.
        i = i + 1
        If i > 100 Then
            i = 0
            DoEvents
        End If
    Loop
End Sub
Example program Chaos uses this code to play the chaos game. Select the File menu's Open command and pick a file with a .cha extension. These files contain a number of anchor points and then list the points.
The following text shows the contents of the file Sierp.cha. The comments to the right make the listing easier to follow and are not part of the file.
e10a6a0a59f035e870d90cca05b85fce.gif
3           ' Number of anchor points.
0.1, 0.9    ' Anchor point 1.
0.5, 0.1    ' Anchor point 2.
0.9, 0.9    ' Anchor point 3.
Using the anchor points defined by file Sierp.cha, program Chaos generates the shape shown in Figure 10.28. The boxes at the corners of the gasket are the anchor points.
Other Gaskets
Program SierpG breaks a triangle into four smaller triangles and removes the middle one. It then recursively calls itself to turn the remaining three triangles into gaskets. You can use a similar technique to create other gaskets.
The following code divides a square into nine smaller squares. It erases the middle square and recursively calls itself to turn the remaining eight squares into gaskets.
e10a6a0a59f035e870d90cca05b85fce.gif
' Erase the center rectangle from this one.
Private Sub SierpinskiErase(ByVal depth As Integer, _
0307-01.gif
Figure 10.28
Program Chaos generating a Sierpinski gasket.

 
< previous page page_307 next page >